How to // Comment
First installation // Première installation

Ubuntu

[Ubuntu] First installation



0. Ensure your system is up to date
  • apt-get update && apt-get upgrade -y
1. Installation useful packets
  • sudo apt-get -y install dos2unix
  • sudo apt-get -y install zip unzip
  • sudo apt install nano
  • sudo apt install bash-completion
  • sudo apt-get -y install mlocate & sudo updatedb

-> In Nano: Use CTRL+K to delete the full line / CTRL-X to exit

2. Secure your server
- Fail2ban
  • apt-get -y install fail2ban
Update "/etc/fail2ban/jail.conf" file (if you have [ssh] inside)
Add or Edit (not remove !) to have following lines:
  • [DEFAULT]
  • ignoreip = 127.0.0.1/8 __YOUR_IP__
  • bantime = 600
  • maxretry = 5
Force reload it with:
  • sudo systemctl restart fail2ban
Check which IP try and fail with:
  • awk '($(NF-1) = /Ban/){print $NF}' /var/log/fail2ban.log | sort | uniq -c | sort -n
- Secure shared memory
  • sudo nano /etc/fstab
Add or Edit (not remove !) to have following lines:
  • tmpfs /dev/shm tmpfs defaults,noexec,nosuid 0 0
- Harden network with sysctl settings
  • sudo nano /etc/sysctl.conf
Add or Edit (not remove !) to have following lines:
  • # IP Spoofing protection
  • net.ipv4.conf.all.rp_filter = 1
  • net.ipv4.conf.default.rp_filter = 1
  • # Ignore ICMP broadcast requests
  • net.ipv4.icmp_echo_ignore_broadcasts = 1
  • # Disable source packet routing
  • net.ipv4.conf.all.accept_source_route = 0
  • net.ipv6.conf.all.accept_source_route = 0
  • net.ipv4.conf.default.accept_source_route = 0
  • net.ipv6.conf.default.accept_source_route = 0
  • # Ignore send redirects
  • net.ipv4.conf.all.send_redirects = 0
  • net.ipv4.conf.default.send_redirects = 0
  • # Block SYN attacks
  • net.ipv4.tcp_syncookies = 1
  • net.ipv4.tcp_max_syn_backlog = 2048
  • net.ipv4.tcp_synack_retries = 2
  • net.ipv4.tcp_syn_retries = 5
  • # Log Martians
  • net.ipv4.conf.all.log_martians = 1
  • net.ipv4.icmp_ignore_bogus_error_responses = 1
  • # Ignore ICMP redirects
  • net.ipv4.conf.all.accept_redirects = 0
  • net.ipv6.conf.all.accept_redirects = 0
  • net.ipv4.conf.default.accept_redirects = 0
  • net.ipv6.conf.default.accept_redirects = 0
  • # Ignore Directed pings
  • net.ipv4.icmp_echo_ignore_all = 1
Force reload it with:
  • sudo sysctl -p
- Prevent IP Spoofing
  • sudo nano /etc/host.conf
Add or Edit (not remove !) to have following lines:
  • order bind,hosts
  • multi on
  • nospoof on
- Harden PHP for security (if you have PHP installed)
  • sudo nano /etc/php5/apache2/php.ini
Add or Edit (not remove !) to have following lines:
  • disable_functions = exec,system,shell_exec,passthru
  • register_globals = Off
  • expose_php = Off
  • magic_quotes_gpc = On
3. Custom startup message
  • sudo apt -y install screenfetch
  • sudo apt -y install toilet
  • sudo apt -y install figlet

-> Upload "clean.sh" and "now.sh" (in /home/Files/) and do "chmod +x clean.sh now.sh" to give it execution right to be able to use it

-> Upload ".profile" (in /home/Files/) to be able to use it

Update "/home/now.sh" file
Add or Edit (not remove !) to have following lines:
  • curl wttr.in/__YOUR_CITY__?0 --silent --max-time 3
Update "~/.bashrc" file
Add or Edit (not remove !) to have following lines:
  • source /home/Files/.profile
Force reload it with:
  • source ~/.bashrc
4. Apache2
  • apt-get install -y apache2 apache2-utils
- Security
Update "/etc/apache2/conf-available/security.conf" file
Add or Edit (not remove !) to have following lines:
  • ServerTokens Prod
  • ServerSignature Off
- Modules
  • sudo rewrite
Force reload it with:
  • service apache2 restart
- Configuration
You can edit /etc/apache2/apache2.conf to add your custom directory rules, like:
  • <Directory /home/canan>
  • Options -Indexes
  • AllowOverride All
  • Require all granted
  • </Directory>
- Index
Do not forget to empty (or put your site) in /var/www/html/ folder
5. PHP (if needed)
  • sudo apt-get install -y php libapache2-mod-php php-gd

-> If you want to test it, simply create a test file, then go on it, finally delete it

Update "/var/www/html/test.php" file (change by yours)
Add to have following lines:
  • <?php
  • phpinfo();
  • ?>
Force reload it with:
  • service apache2 restart
Go to http://__YOUR_IP__/test.php
6. Crontab
  • crontab -e
Add or Edit (not remove !) to have following lines :
  • 10 5 * * MON apt-get -y autoclean; apt-get -y autoremove; apt-get -y clean;
  • 20 5 * * MON dpkg --purge $(COLUMNS=200 dpkg -l | grep "^rc" | tr -s ' ' | cut -d ' ' -f 2);
  • 30 5 * * MON rm -fr /var/log/syslog.*; rm -fr /var/log/auth.log.*;
  • 40 5 * * MON apt-get -y update; apt-get -y upgrade


How to

[How to] Première installation



0. Assurez-vous que votre système est à jour
  • apt-get update && apt-get upgrade -y
1. Installation des paquets utiles
  • sudo apt-get -y install dos2unix
  • sudo apt-get -y install zip unzip
  • sudo apt install nano
  • sudo apt install bash-completion
  • sudo apt-get -y install mlocate & sudo updatedb

-> Dans nano: utilisez CTRL+K pour supprimer la ligne complète / CTRL-X pour quitter

2. Sécurisez votre serveur
- Fail2ban
  • apt-get -y install fail2ban
Mettre à jour le fichier "/etc/fail2ban/jail.conf" (si vous avez [ssh] à l'intérieur)
Ajouter ou modifier (ne pas supprimer !) pour avoir les lignes suivantes :
  • [DEFAULT]
  • ignoreip = 127.0.0.1/8 __VOTRE_IP__
  • bantime = 600
  • maxretry = 5
Forcer à le recharger avec :
  • sudo systemctl restart fail2ban
Vérifiez quel IP essayer et échouer avec :
  • awk '($(NF-1) = /Ban/){print $NF}' /var/log/fail2ban.log | sort | uniq -c | sort -n
- Mémoire partagée sécurisée
  • sudo nano /etc/fstab
Ajouter ou modifier (ne pas supprimer !) pour avoir les lignes suivantes :
  • tmpfs /dev/shm tmpfs defaults,noexec,nosuid 0 0
- Durcir le réseau avec les paramètres sysctl
  • sudo nano /etc/sysctl.conf
Ajouter ou modifier (ne pas supprimer !) pour avoir les lignes suivantes :
  • # IP Spoofing protection
  • net.ipv4.conf.all.rp_filter = 1
  • net.ipv4.conf.default.rp_filter = 1
  • # Ignore ICMP broadcast requests
  • net.ipv4.icmp_echo_ignore_broadcasts = 1
  • # Disable source packet routing
  • net.ipv4.conf.all.accept_source_route = 0
  • net.ipv6.conf.all.accept_source_route = 0
  • net.ipv4.conf.default.accept_source_route = 0
  • net.ipv6.conf.default.accept_source_route = 0
  • # Ignore send redirects
  • net.ipv4.conf.all.send_redirects = 0
  • net.ipv4.conf.default.send_redirects = 0
  • # Block SYN attacks
  • net.ipv4.tcp_syncookies = 1
  • net.ipv4.tcp_max_syn_backlog = 2048
  • net.ipv4.tcp_synack_retries = 2
  • net.ipv4.tcp_syn_retries = 5
  • # Log Martians
  • net.ipv4.conf.all.log_martians = 1
  • net.ipv4.icmp_ignore_bogus_error_responses = 1
  • # Ignore ICMP redirects
  • net.ipv4.conf.all.accept_redirects = 0
  • net.ipv6.conf.all.accept_redirects = 0
  • net.ipv4.conf.default.accept_redirects = 0
  • net.ipv6.conf.default.accept_redirects = 0
  • # Ignore Directed pings
  • net.ipv4.icmp_echo_ignore_all = 1
Forcer à le recharger avec :
  • sudo sysctl -p
- Prévenir IP Spoofing
  • sudo nano /etc/host.conf
Ajouter ou modifier (ne pas supprimer !) pour avoir les lignes suivantes :
  • order bind,hosts
  • multi on
  • nospoof on
- Harden PHP pour la sécurité (si vous avez installé PHP)
  • sudo nano /etc/php5/apache2/php.ini
Ajouter ou modifier (ne pas supprimer !) pour avoir les lignes suivantes :
  • disable_functions = exec,system,shell_exec,passthru
  • register_globals = Off
  • expose_php = Off
  • magic_quotes_gpc = On
3. Message de démarrage personnalisé
  • sudo apt -y install screenfetch
  • sudo apt -y install toilet
  • sudo apt -y install figlet

-> Uploadez "clean.sh" et "now.sh" (in /home/Files/) et effectué "chmod +x clean.sh now.sh" pour lui donner le droit d'exécution pour pouvoir l'utiliser

-> Uploadez ".profile" (in /home/Files/) pour lui donner le droit d'exécution pour pouvoir l'utiliser

Mettre à jour le fichier "/home/now.sh"
Ajouter ou modifier (ne pas supprimer !) pour avoir les lignes suivantes :
  • curl wttr.in/__YOUR_CITY__?0 --silent --max-time 3
Mettre à jour le fichier "~/.bashrc"
Ajouter ou modifier (ne pas supprimer !) pour avoir les lignes suivantes :
  • source /home/Files/.profile
Forcer à le recharger avec :
  • source ~/.bashrc
4. Apache2
  • apt-get install -y apache2 apache2-utils
- Securité
Mettre à jour le fichier "/etc/apache2/conf-available/security.conf"
Ajouter ou modifier (ne pas supprimer !) pour avoir les lignes suivantes :
  • ServerTokens Prod
  • ServerSignature Off
- Modules
  • sudo rewrite
Forcer à le recharger avec :
  • service apache2 restart
- Configuration
Vous pouvez éditer /etc/apache2/apache2.conf pour ajouter vos règles de répertoire personnalisées, comme :
  • <Directory /home/canan>
  • Options -Indexes
  • AllowOverride All
  • Require all granted
  • </Directory>
- Index
N'oubliez pas de vider (ou de mettre votre site) dans le dossier /var/www/html/
5. PHP (si besoin)
  • sudo apt-get install -y php libapache2-mod-php php-gd

-> Si vous voulez le tester, créez simplement un fichier de test, puis continuez et finalement supprimez-le.

Mettre à jour le fichier "/var/www/html/test.php" (changer par le vôtre)
Ajouter pour avoir les lignes suivantes :
  • <?php
  • phpinfo();
  • ?>
Forcer à le recharger avec :
  • service apache2 restart
Allez sur http://__VOTRE_IP__/test.php
6. Crontab
  • crontab -e
Ajouter ou modifier (ne pas supprimer !) pour avoir les lignes suivantes :
  • 10 5 * * MON apt-get -y autoclean; apt-get -y autoremove; apt-get -y clean;
  • 20 5 * * MON dpkg --purge $(COLUMNS=200 dpkg -l | grep "^rc" | tr -s ' ' | cut -d ' ' -f 2);
  • 30 5 * * MON rm -fr /var/log/syslog.*; rm -fr /var/log/auth.log.*;
  • 40 5 * * MON apt-get -y update; apt-get -y upgrade;